<HTML><HEAD><TITLE>arity(+Term, -Arity)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Term Manipulation</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>arity(+Term, -Arity)</H1>
Succeeds if Arity is the arity of Term.
<DL>
<DT><EM>Term</EM></DT>
<DD>Prolog term.
</DD>
<DT><EM>Arity</EM></DT>
<DD>Variable or integer.
</DD>
</DL>
<H2>Description</H2>

    If Term is instantiated, its arity (number of arguments) is unified
    with Arity.  For compound terms, this is the number of arguments,
    for atomic terms it is 0.  As usual, non-empty lists are considered
    compound terms with arity 2.
<P>
    Note that (like all predicates that return a number as their last
    argument), this predicate can be used as a function inside arithmetic
    expressions, e.g.
<PRE>
	..., (I > arity(Term) -> writeln(error), fail ; arg(I, Term, Arg) ).
</PRE>

<H3>Modes and Determinism</H3><UL>
<LI>arity(+, -) is det
</UL>
<H3>Exceptions</H3>
<DL>
<DT><EM>(4) instantiation fault </EM>
<DD>Term is uninstantiated (non-coroutine mode only).
</DL>
<H2>Examples</H2>
<PRE>
Success:
   arity(f(1,2),2).
   arity(f(1,2),A).    (gives A=2).
   arity([],A).        (gives A=0).
   arity("s",A).     (gives A=0).
   arity(33,A).        (gives A=0).

Fail:
   arity(f(1,2),3).
   arity("compound(g)",1).

Error:
   arity(_,A).         (Error 4).
</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/termmanip/EDD-2.html">=.. / 2</A>, <A HREF="../../kernel/termmanip/arg-3.html">arg / 3</A>, <A HREF="../../kernel/termmanip/functor-3.html">functor / 3</A>
</BODY></HTML>
